//
//  LcJson.h
//  18Birdies
//
//  Created by Lc on 15/3/15.
//  Copyright (c) 2015年 Lc. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "LcSingleton.h"

@protocol LcTypeAdapter;

@interface LcJson : LcSingleton

- (void)registerTypeAdapter:(id<LcTypeAdapter>)typeAdapter
                    forType:(NSString*)type;
- (void)registerSubclassAdapterForType:(NSString*)type
               withDefaultSubclassType:(NSString*)defaultSubclassType;

- (id)fromJson:(NSData*)data ofClass:(Class)clazz;
- (NSData*)toJson:(id)object;

- (id)fromJson:(NSData*)data
             ofClass:(Class)clazz
    withGenericTypes:(NSArray*)genericTypes;
- (NSData*)toJson:(id)object
          ofClass:(Class)clazz
 withGenericTypes:(NSArray*)genericTypes;

- (BOOL)jsonEquals:(id)object1 with:(id)object2;
// not support generic types
- (id)jsonCopy:(id)object;

+ (NSString*)typeNameOfProtocol:(Protocol*)protocol;

/*
 Can be called from subclass adapter
 */
- (id)fromJsonElement:(id)jsonElement
               toType:(NSString*)type
     withGenericTypes:(NSArray*)genericTypes
      skipTypeAdapter:(BOOL)skipTypeAdapter;
- (id)toJsonElement:(id)object
     ofDeclaredType:(NSString*)declaredType
   withGenericTypes:(NSArray*)genericTypes
    skipTypeAdapter:(BOOL)skipTypeAdapter;

- (BOOL) isJsoning;

@end

@protocol LcJsonGenericTypeCallback
@required
+ (NSArray*)genericTypesOfProperty:(NSString*)propertyName;
@end
